import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { ThemeProvider, createTheme, CssBaseline } from '@mui/material';
import Chat from './pages/Chat';
import Login from './pages/Login';
import Register from './pages/Register';
import PrivateRoute from './components/PrivateRoute';
import UserManagement from './pages/UserManagement';
import DataUpload from './pages/DataUpload';
import SummarySearch from './pages/SummarySearch';
import { UserProvider } from './contexts/UserContext';

// 创建自定义主题
const theme = createTheme({
  palette: {
    primary: {
      main: '#10a37f',  // GPT风格的绿色
      light: '#1dd1a1',
      dark: '#0c8c6e',
      contrastText: '#fff',
    },
    secondary: {
      main: '#6c5ce7',
      light: '#a29bfe',
      dark: '#5541d7',
    },
    background: {
      default: '#f5f5f5',
      paper: '#fff',
    },
    text: {
      primary: '#202123',
      secondary: '#6e6e80',
    },
  },
  typography: {
    fontFamily: "'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
  },
  shape: {
    borderRadius: 8,
  },
  components: {
    MuiButton: {
      styleOverrides: {
        root: {
          textTransform: 'none',
          fontWeight: 500,
        },
      },
    },
    MuiPaper: {
      styleOverrides: {
        root: {
          boxShadow: '0 2px 6px rgba(0, 0, 0, 0.05)',
        },
      },
    },
  },
});

const App: React.FC = () => {
  return (
    <ThemeProvider theme={theme}>
      <CssBaseline />
      <UserProvider>
        <Router>
          <Routes>
            <Route path="/login" element={<Login />} />
            <Route path="/register" element={<Register />} />
            <Route 
              path="/chat" 
              element={
                <PrivateRoute>
                  <Chat />
                </PrivateRoute>
              } 
            />
            <Route 
              path="/user-management" 
              element={
                <PrivateRoute requiredRole="admin">
                  <UserManagement />
                </PrivateRoute>
              } 
            />
            <Route 
              path="/data-upload" 
              element={
                <PrivateRoute>
                  <DataUpload />
                </PrivateRoute>
              } 
            />
            <Route 
              path="/summary-search" 
              element={
                <PrivateRoute>
                  <SummarySearch />
                </PrivateRoute>
              } 
            />
            <Route path="/" element={<Navigate to="/chat" replace />} />
          </Routes>
        </Router>
      </UserProvider>
    </ThemeProvider>
  );
};

export default App;
